package orderProcessingProcess.model;

import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author dreni
 */
@XmlRootElement(name="item")
public class Item {

    private int quantity;
    private String product_id;
    private BigDecimal single_unit_price;
    private Order order;

    public Item (int quantity, String product_id, BigDecimal single_unit_price, Order order){
        this.quantity = quantity;
        this.product_id = product_id;
        this.single_unit_price = single_unit_price;
        this.order = order;
    }

    public Item (){
    }

    /**
     * @return the quantity
     */
    @XmlElement(name="quantity", required =true)
    public int getQuantity() {
        return quantity;
    }

    /**
     * @param quantity the quantity to set
     */
    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    /**
     * @return the product_id
     */
    @XmlAttribute(name="productID", required =true)
    public String getProduct_id() {
        return product_id;
    }

    /**
     * @param product_id the product_id to set
     */
    public void setProduct_id(String product_id) {
        this.product_id = product_id;
    }

    /**
     * @return the single_unit_price
     */
    @XmlElement(name="singleUnitPrice", required =true)
    public BigDecimal getSingle_unit_price() {
        return single_unit_price;
    }

    /**
     * @param single_unit_price the single_unit_price to set
     */
    public void setSingle_unit_price(BigDecimal single_unit_price) {
        this.single_unit_price = single_unit_price;
    }

	/**
	 * @return the order
	 */
    @XmlTransient
    public Order getOrder() {
		return order;
	}

	/**
	 * @param order the order to set
	 */
	public void setOrder(Order order) {
		this.order = order;
	}
    
    @Override
    public boolean equals(Object obj) {
    	if(obj.getClass().equals(Item.class))
    	{
    		if(this.product_id.equals(((Item)obj).getProduct_id()))
    			return true;
    	}
        return false;
    }

    @Override
    public int hashCode() {
        return this.product_id.hashCode();
    }
}
